<template>
  <div>
    <div v-for="(item, index) in data" :key="index">
      商品名：{{ item.name }} --- 价格：{{ item.price }} --- 库存：{{ item.inventory }}
      <button @click="update(item)">修改</button>
      <button @click="del(item)">删除</button>
    </div>
  </div>
</template>

<script>
import {goods} from "@/api/goods";

export default {
  data(){
    return {
      data:[]
    }
  },
  methods: {
    async updateSubmit() {
      this.updateOpen = false
      await goods.updateGoods(this.createParams.id, this.createParams)
      this.$forceUpdate();
      this.createParams = {}
    },
    async submit() {
      this.open = false
      await goods.createGoods(this.createParams)
      this.$forceUpdate();
      this.createParams = {}
    },
    add() {
      this.open = true
    },
    update(item) {
      // console.log("update",item)
      this.$emit('isUpdate',item)
      // this.updateOpen = true
      // this.createParams.name = item.name
      // this.createParams.price = item.price
      // this.createParams.inventory = item.inventory
      // this.createParams.id = this.data.indexOf(item)
    },
    async del(item) {
      console.log(item)
      goods.delGoods(this.data.indexOf(item))
      this.$forceUpdate();
    }
  },
  async created() {
    this.data = await goods.getGoods()
    this.$forceUpdate();
  },
}
</script>

<style scoped>

</style>
